
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>菜单角色管理</title>
<link href="<c:url value='/insdep/reset.min.css' />" rel="stylesheet" type="text/css">
<link href="<c:url value='/insdep/easyui_full.css'/>" rel="stylesheet" type="text/css">
<link href="<c:url value='/insdep/icon.css'/>" rel="stylesheet" type="text/css">
<script type="text/javascript" src="<c:url value='/insdep/jquery-1.11.3.min.js'/>"></script>
<script type="text/javascript" src="<c:url value='/insdep/jquery.easyui-1.5.2.min.js'/>"></script>
<script type="text/javascript" src="<c:url value='/insdep/insdep-extend.min.js'/>"></script>
<link rel="stylesheet" type="text/css" href="<c:url value='/insdep/iconfont/iconfont.css' />">
<link href="<c:url value='/css/wsf-button.css'/>" rel="stylesheet" type="text/css">
</head>
<body>
<script type="text/javascript">
$(document).ready(function(){
	//按条件查询用户
	 $("#menurole_query_searcher_btn").linkbutton({onClick:function(){ 
		 $('#member_search_from').form('submit', {   
			 	onSubmit: function(param){    
			        param.page = '1';    
			        param.rows = '2';    
			    },
			    success:function(data){    //表单查询数据刷新DataGrid
			    	var resultData = $.parseJSON(data);    
			    	$('#menurole_info_dg').datagrid('loadData', resultData); 
			    }    
			}); 
	 }});
	//分页将参数带过去
	$("#menurole_info_dg").datagrid({
		onBeforeLoad:function(param){
			param.roleName=$("#roleName").val();
		}
	});
	//重置
	 $("#menurole_reset_btn").linkbutton({onClick:function(){  
		 $("#member_search_from").form('reset');
		 $("#menurole_info_dg").datagrid('load', {}); 
	 }});
	//刷新
	 $("#menuRole_Refresh").linkbutton({onClick:function(){
			$('#menurole_info_dg').datagrid('reload');  
	 }});
   	//新建菜单角色
   	 $("#menuRole_createUser").linkbutton({onClick:function(){
   		 $("#create_new_menurole_win").window({
		      width: 400,
	          height: 370,
	          title: '新建角色信息窗口',
	          iconCls: 'icon-update',
	          modal: true,//表示模式窗口
	          maximizable:false,
	          minimizable:false,
	          collapsible:false,
	          draggable: false ,
			  href:'to_createMenuRole',//请求远程数据
			  onLoad : function() {
				  $('#createMenuRole').form('load',{
					 roleId:0,
					 roleDesc:null,
					 roleName:null,
					 status:true
		    		});
				}
			});
   	 }
   	 });
   	/**
 	 *关闭分配权限窗口即保存权限
 	 */
 	 
});

	function menurole_state(val) {
		return {0:"不可用", 1:"可用"}[val];
	}
	/**
	 * 提交编辑后的权限信息
	 */
	function save_editiInfo(){
			var giveroleid=$("#give_menurole_power_win").window("options").roleid;
				var checkednodes = $('#menurole_tree').tree('getChecked');
				var funIds = [];
				for (var i = 0; i < checkednodes.length; i++) {
				if(!checkednodes[i].children){
					funIds.push(checkednodes[i].id);
				}
			}
			//提交表单
			$("<form method='post'>").form({
				url:'give_MenuRolePermissions',
				onSubmit:function(params){
					params.perids=funIds;
					params.roleid=giveroleid;
				},
				success:function(info){
					$('#give_menurole_power_win').window('close');
					$('#menurole_info_dg').datagrid('reload');
				}
			}).submit();
			
	}
	/**
	 *提交编辑后的指定用户
	 */
	function save_editempids(){
			var giveroleid=$("#give_emp_menurole_win").window("options").roleid;
	 		var checkednodes = $('#rolename_tree').tree('getChecked');
	 		var empids = [];
	 		for (var i = 0; i < checkednodes.length; i++) {
	 			if(!checkednodes[i].children){
	 					empids.push(checkednodes[i].id);
	 			}
	 		}
	 		//提交表单
	 		$("<form method='post'>").form({
	 			url:'give_MenuRoleEmp',
	 			onSubmit:function(params){
	 				params.empids=empids;
	 				params.roleid=giveroleid;
	 			},
	 			success:function(info){
					$('#give_emp_menurole_win').window('close');
	 				$('#menurole_info_dg').datagrid('reload');
	 			}
	 		}).submit();
	 	
	}
	/**
	 *编辑菜单角色
	 */
	function edit(index){
	    	$('#menurole_info_dg').datagrid('selectRow',index);
	     	var row = $('#menurole_info_dg').datagrid('getSelected');
			var checkedd = row.roleState=='1'?true:false;
	     	if (row){  
	     	    $("#create_new_menurole_win").window({
	 		      width: 400,
	 	          height: 370,
	 	          title: '修改角色信息窗口',
	 	          iconCls: 'icon-update',
	 	          modal: true,//表示模式窗口
	 	          maximizable:false,
	 	          minimizable:false,
	 	          collapsible:false,
	 	          draggable: false ,
	 			  href:'to_createMenuRole',//请求远程数据
	 			  onLoad : function() {
	 				  $('#createMenuRole').form('load',{
	 					 roleId:row.roleId,
	 					 roleDesc:row.roleDesc,
	 					 roleName:row.roleName
	 		    		});
	 				  //switchbutton初始化
	 				  $("#sstt").switchbutton({
	 					  checked: checkedd
	 				    });
	 				}
	 			});
	     	}
	     };  
	/**
	 *删除菜单角色
	 */
	function remove_role(index){
    	$('#menurole_info_dg').datagrid('selectRow',index);
     	var row = $('#menurole_info_dg').datagrid('getSelected');
     	$.messager.confirm('提示', '您确认删除吗？', function(r){
			if (r){
			    // 确认;
				$.post("remove_menuRole",{roleId:row.roleId, roleDesc:row.roleDesc, roleName:row.roleName, roleState:row.roleState}, 
				        function(data){
						//*刷新数据
						if(data){
							$('#menurole_info_dg').datagrid('reload');
							//提示信息
							$.messager.show({
								title:'提示',
								msg:'删除成功！', 
							    timeout:1000,  
								showType:'show',
								style:{
						            right:'',  
						            bottom:'' 
								}
							});
						}else{
							//提示信息
							$.messager.show({
								title:'提示',
								msg:'删除失败！', 
							    timeout:1000,  
								showType:'show',
								style:{
						            right:'',  
						            bottom:'' 
								}
							});
						}
							
				});
			}
		});
        
	}
	/**
	 *开启分配权限窗口
	 */
	function give_power(index){
    	$('#menurole_info_dg').datagrid('selectRow',index);
     	var row = $('#menurole_info_dg').datagrid('getSelected'); 
		$("#give_menurole_power_win").window({
		      width: 300,
	          height: 500,
	          title: '分配权限',
	          iconCls: 'icon-update',
	          modal: true,//表示模式窗口
	          maximizable:false,
	          minimizable:false,
	          collapsible:false,
	          draggable: true,
			  href:'to_functionTree',//请求远程数据rows.roleId
			  roleid:row.roleId
			});
	}
	/**
	 *给角色指定用户
	 */
	function give_emp(index){
	    $('#menurole_info_dg').datagrid('selectRow',index);
	    var row = $('#menurole_info_dg').datagrid('getSelected'); 
	    $("#give_emp_menurole_win").window({
		      width: 300,
	          height: 500,
	          title: '指定用户',
	          iconCls: 'icon-update',
	          modal: true,//表示模式窗口
	          maximizable:false,
	          minimizable:false,
	          collapsible:false,
	          draggable: true,
			  href:'to_GiveRoleIsEmp',//请求远程数据rows.roleId
			  roleid:row.roleId
		});
	}
	/**
	 *角色详情函数
	 */
	function menurole_desc(index){
		$('#menurole_info_dg').datagrid('selectRow',index);
	    var row = $('#menurole_info_dg').datagrid('getSelected'); 
	    $("#menurole_desc_win").window({
		      width: 500,
	          height: 600,
	          title: '角色详情',
	          iconCls: 'icon-update',
	          modal: true,//表示模式窗口
	          maximizable:false,
	          minimizable:false,
	          collapsible:false,
	          roleid:row.roleId,
	          draggable: true,
			  href:'to_MenuRoleDesc',//请求远程数据rows.roleId
			  roleid:row.roleId
		});
	}
	 
 	/**
	 *操作
	 */
	function action(val,row,index) {
		var edit = "", remove = "", givepower = "", giveemp = "", roledesc = "";
		edit = '<a class="button-teal iconfont icon-shenqingshenpi" style="color:white;padding:5px 7px;font-size:14px;margin-right:3%" onclick="edit('+index+')">编辑</a>';
		remove = '<a class="button-teal iconfont icon-delete" style="color:white;padding:5px 7px;font-size:14px;margin-right:3%" onclick="remove_role('+index+')">删除</a>';
		givepower = '<a class="button-blue iconfont icon-command" style="color:white;padding:5px 7px;font-size:14px;margin-right:3%" onclick="give_power('+index+')">分配权限</a>';
		giveemp = '<a class="button-blue iconfont icon-expressman" style="color:white;padding:5px 7px;font-size:14px;margin-right:3%" onclick="give_emp('+index+')">指定用户</a>';
		roledesc = '<a class="button-darkblue iconfont icon-gonggao" style="color:white;padding:5px 7px;font-size:14px;margin-right:3%" onclick="menurole_desc('+index+')">角色详情</a>';
		return edit+remove+givepower+giveemp+roledesc;
	}
</script>
<div class="easyui-layout" data-options="fit:true">
	<!--查询表单  --> 
    <div data-options="region:'north',title:'用户管理',split:true,collapsed:true" style="padding:10px;height:100px;">
    	<form action="get_menuRole" id="member_search_from" class="searcher-form" method="post">
			<input name="roleName" id="roleName" class="easyui-textbox field" label="角色名称："  labelWidth="70" style="width:300px">
    		<a id="menurole_query_searcher_btn" class="easyui-linkbutton" data-options="iconCls:'icon-search'">检索</a>
			<a id="menurole_reset_btn" class="easyui-linkbutton" data-options="iconCls:'icon-reload'">重置</a>
    	</form>
    </div> 
    <!--数据表格  --> 
    <div data-options="region:'center',border:false" style="border-top: 1px solid #D3D3D3">
		<table id="menurole_info_dg" class="easyui-datagrid" 
		data-options="
		fit:true,
		fitColumns:true,
		url:'get_menuRole',
		rownumbers: true,
		toolbar: '#tb',
		nowrap:false, 
		autoRowHeight:true,
		autoRowWidth:300,
		pagination:true,
		pageSize: 2,
		pageList:[2,4,6,8]">
		<thead>
				<tr>
				<th style="width:10%;height:60px;" data-options="field:'roleId', align:'center', sortable:true">角色编号</th>
				<th style="width:10%;height:60px;" data-options="field:'roleName', align:'center'">角色名称</th>
				<th style="width:31.7%;height:60px;" data-options="field:'roleDesc', align:'center'">角色描述</th>
				<th style="width:10%;height:60px;" data-options="field:'roleState', align:'center', formatter:menurole_state">可用状态</th>
				<th data-options="field:'test', formatter:action, align:'center',width:'40%'">操作</th>
			</tr>
		</thead>
		</table>
    </div>
    </div> 
    
    
    
    <!--easyui-datagrid当中的工具栏  -->
    <div id="tb">
    		<a id="menuRole_createUser" class="easyui-linkbutton" data-options="iconCls:'icon-add'">创建</a>
    		<a id="menuRole_Refresh" class="easyui-linkbutton" data-options="iconCls:'icon-reload'">刷新</a>
    </div>  
 
<!--点击工具栏弹出的新建用户window -->
<div id="create_new_menurole_win"></div>
<!--点击工具栏弹出的分配权限window -->
<div id="give_menurole_power_win"></div>
<!--点击工具栏弹出的指定用户window -->
<div id="give_emp_menurole_win"></div>
<!--点击工具栏弹出的角色详情window -->
<div id="menurole_desc_win"></div>

</body> 
</html>